home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2005 March / Macworld CD March 2005 - Marathon Trilogy.iso / Shareware World / Text Processing / HexEdit Release.sit / HexEdit Release / Project / Source / AboutBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-30  |  6.9 KB  |  264 lines  |  [TEXT/CWIE]

  1. /*
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Initial Developer of the Original Code is Lane Roathe
  13.  * Portions created by Lane Roathe are
  14.  * Copyright (C) Copyright © 1996-2002.
  15.  * All Rights Reserved.
  16.  *
  17.  * Modified: $Date: 2002/08/21 05:54:30 $
  18.  * Revision: $Id: AboutBox.c,v 1.14 2002/08/21 05:54:30 raving Exp $
  19.  *
  20.  * Contributor(s):
  21.  *        Lane Roathe
  22.  *        Greg Branche
  23.  */
  24.  
  25. // 05/10/01 - GAB: MPW environment support
  26. #ifdef __MPW__
  27. #include "MPWIncludes.h"
  28. #endif
  29.  
  30. #include "Main.h"
  31. #include "ObjectWindow.h"
  32. #include "Utility.h"
  33.  
  34. #include "AboutBox.h"
  35.  
  36. /* if not carbon, appearance manager might not be available and we need these */
  37. #if !TARGET_API_MAC_CARBON
  38.     static TEHandle    hTE;
  39.     static short endText;
  40.     static long long prevTime;
  41.  
  42.     #define TEITEM        2
  43.  
  44.     //LR 1.76 -- rewrite entire text scroll routine to do speed based on pixels per second!
  45.     #define SCROLLPIXELSPERSECOND 10.0    // NOTE: good to keep in even ticks for update cleanness
  46.     #define BLANKPIXELSPACE 190            //LR 181 -- blank spacing in text for autoscroll use
  47. #endif
  48.  
  49. #define kFirstURLItem 6    // all the rest must follow WITHOUT BREAKS!
  50.  
  51. //LR 1.73 -- make code more readable
  52. #ifdef __MC68K__
  53.     #define PLATFORM_STRING "\p68K"
  54. #elif TARGET_API_MAC_CARBON
  55.     #define PLATFORM_STRING    "\pCarbon"
  56. #elif TARGET_CPU_PPC
  57.     #define PLATFORM_STRING    "\pPPC"
  58. #else
  59.     #define PLATFORM_STRING "\pUKNOWN!"
  60. #endif
  61.  
  62. /* --- new dialog method in carbon makes scrolling much better, esp. in X! */
  63.  
  64. #if !TARGET_API_MAC_CARBON
  65.  
  66. /*** DRAW TE TEXT ***/
  67. //    draw the TE text in our user item
  68. static pascal void _updateTextBox( DialogPtr whichDialog, short itemNr )
  69. {
  70.     #pragma unused( itemNr )
  71.  
  72.     GrafPtr savePort;
  73.  
  74.     // let the standard dialog filter handle events
  75.     GetPort( &savePort );
  76.     SetPortDialogPort( whichDialog );
  77.  
  78.     TEUpdate( &(*hTE)->viewRect, hTE );
  79.  
  80.     SetPort( savePort );
  81. }
  82.  
  83. /*** DIALOG FILTER ***/
  84. //    dialog filter for about box (used to scroll TE contents)
  85. static pascal Boolean _standardFilter( DialogPtr whichDialog, EventRecord *event, short *itemHit )
  86. {
  87.     long long curTime;
  88.     double elapsed;
  89.     int pixels;
  90.  
  91.     // Get elapsed time in seconds. (makes the constant definition easier to set)
  92.     Microseconds( (UnsignedWide *)&curTime );
  93.     elapsed = (double)(prevTime - curTime);        // get's us a negative, which is what we want!
  94.     elapsed /= 10000.0;
  95.  
  96.     // how many pixels should we scroll?
  97.     // In Classic this will usually be 0 or 1, in X is normally 5 or more!
  98.     pixels = (int)(elapsed / (60.0 / SCROLLPIXELSPERSECOND));
  99.     if( pixels )
  100.     {
  101.         Microseconds( (UnsignedWide *)&prevTime );    // reset time check
  102.  
  103.         if( (*hTE)->destRect.bottom >= endText )
  104.         {
  105.             TEScroll( 0, pixels, hTE );    // show text slowly (causes update event)
  106.         }
  107.         else    // end of credits, start from the top!
  108.         {
  109.             register short startOffset = ((*hTE)->viewRect.bottom - (*hTE)->viewRect.top) - BLANKPIXELSPACE;
  110.     
  111.             (*hTE)->destRect.top = (*hTE)->viewRect.top + startOffset;
  112.             (*hTE)->destRect.bottom = (*hTE)->viewRect.bottom + startOffset;
  113.         }
  114.     }
  115.  
  116.     // let the standard dialog filter handle events
  117.     return StdFilterProc( whichDialog, event, itemHit );
  118. }
  119.  
  120. #endif //!TARGET_API_MAC_CARBON
  121.  
  122. static pascal Boolean _appearanceFilter( DialogPtr whichDialog, EventRecord *event, short *itemHit )
  123. {
  124.     Boolean handled = false;
  125.  
  126.     // let background windows update
  127.     if( updateEvt == event->what )
  128.     {
  129.         ObjectWindowPtr objectWindow;
  130.         WindowRef theWin = (WindowRef) event->message;
  131.  
  132.         objectWindow = (ObjectWindowPtr) GetWRefCon( theWin );
  133.         if( GetWindowKind( theWin ) == kHexEditWindowTag && objectWindow->Update )
  134.             objectWindow->Update( theWin );
  135.     }
  136.     else
  137.     {
  138.         GrafPtr savePort;
  139.  
  140.         // let the standard dialog filter handle events
  141.         GetPort( &savePort );
  142.         SetPortDialogPort( whichDialog );
  143.         handled = StdFilterProc( whichDialog, event, itemHit );
  144.         SetPort( savePort );
  145.     }
  146.  
  147.     return( handled );
  148. }
  149.  
  150.  
  151. /*** HEX EDIT ABOUT BOX ***/
  152. //    code stolen from Lane's ResCon sources
  153. void HexEditAboutBox( void )
  154. {
  155.     DialogPtr    theDialog;
  156.     short        item;
  157.     GrafPtr        savePort;
  158.     StringPtr    verStr;
  159.     VersRecHndl    vr;
  160.     short        dialogID;
  161.     ModalFilterUPP dlgFilterUPP;
  162.  
  163. #if !TARGET_API_MAC_CARBON
  164.     Handle        text;
  165.     StScrpHandle style;
  166.     Rect        bounds;
  167.  
  168.     UserItemUPP userItemUPP = NewUserItemUPP( _updateTextBox );
  169. #endif
  170.  
  171.     /* select which filter proc we want to use */
  172.     if( g.useAppearance )
  173.     {
  174.         dialogID = dlgAbout;
  175.         dlgFilterUPP = NewModalFilterUPP( _appearanceFilter );
  176.     }
  177. #if !TARGET_API_MAC_CARBON
  178.     else
  179.     {
  180.         dialogID = dlgAbout + 1;
  181.         dlgFilterUPP = NewModalFilterUPP( _standardFilter );
  182.     }
  183. #endif
  184.  
  185.     /* First, get our version information to display in dialog */
  186.     if( ( vr = (VersRecHndl)GetResource( 'vers', 1 )) != NULL )
  187.     {
  188.         HLock( (Handle)vr );
  189.         verStr = (StringPtr)(((unsigned long)&(** vr).shortVersion[0]));
  190.     }
  191.     else
  192.         verStr = "\p(unknown version)";
  193.  
  194.     ParamText( verStr, PLATFORM_STRING, NULL, NULL );
  195.  
  196.     if( vr )
  197.         ReleaseResource( (Handle)vr );    //LR 1.73 -- just to be safe
  198.  
  199.     /* Create the dialog */
  200.     GetPort( &savePort );
  201.  
  202.     theDialog = GetNewDialog( dialogID, NULL, kFirstWindowOfClass );
  203.     SetPortDialogPort( theDialog );
  204.  
  205.     /* W/O appearance manager we must create scrolling box ourselves! */
  206. #if !TARGET_API_MAC_CARBON
  207.     if( !g.useAppearance )
  208.     {
  209.         /* Get the text to display */
  210.         GetRect( theDialog, TEITEM, &bounds );
  211.         hTE = TEStyleNew( &bounds, &bounds );
  212.         TEScroll( 0, ((*hTE)->viewRect.bottom - (*hTE)->viewRect.top) - BLANKPIXELSPACE, hTE );
  213.  
  214.         style = (StScrpHandle)GetResource( 'styl', dlgAbout );        // try to use a styled text edit for coolness
  215.         text = GetResource ('TEXT', dlgAbout);
  216.         if( text )
  217.         {
  218.             HLock( text );
  219.             TEStyleInsert (&(**text), GetHandleSize (text), style, hTE);    // Style == 0 creates plain text
  220.             ReleaseResource( text );
  221.         }
  222.  
  223.         TECalText( hTE );
  224.         endText = (((*hTE)->destRect.top + BLANKPIXELSPACE) - (TEGetHeight( (*hTE)->nLines, 1, hTE ) - BLANKPIXELSPACE));    // bottom < this == done
  225.  
  226.         SetDraw( theDialog, TEITEM, (Handle) userItemUPP );
  227.  
  228.         Microseconds( (UnsignedWide *)&prevTime );
  229.     }
  230. #endif //!TARGET_API_MAC_CARBON
  231.  
  232.     /* Show the dialog and run it */
  233.     SetDialogDefaultItem( theDialog, ok );
  234.     ShowWindow( GetDialogWindow( theDialog ) );
  235.  
  236.     InitCursor();
  237.  
  238.     ModalDialog( dlgFilterUPP, &item );
  239.  
  240.     // LR: 1.66 check for a URL item and launch if so
  241. #ifndef __MC68K__
  242.     if( kFirstURLItem <= item )
  243.     {
  244.         Str255 str;
  245.         GetIndString( str, strURLs, item - (kFirstURLItem - 1) );
  246.         LaunchURL( str );
  247.     }
  248. #endif
  249.  
  250. #if !TARGET_API_MAC_CARBON
  251.     if( !g.useAppearance )
  252.     {
  253.         TEDispose( hTE );
  254.         DisposeUserItemUPP( userItemUPP );
  255.     }
  256. #endif //!TARGET_API_MAC_CARBON
  257.  
  258.     DisposeModalFilterUPP( dlgFilterUPP );
  259.  
  260.     DisposeDialog( theDialog );
  261.  
  262.     SetPort( savePort );
  263. }
  264.